package com.xmz.controller;

import com.xmz.entity.Book;
import com.xmz.service.BookService;
import com.xmz.util.PageResult;
import com.xmz.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xmz.vo.BookVo;

import java.util.List;


@RestController
@RequestMapping("/book")
@CrossOrigin
public class BookController {

    @Autowired
    private BookService bookService;

    @PostMapping("/loadList")
    public PageResult<Book> loadList(Integer pageNo, Integer pageSize, @RequestBody BookVo searchBook){
        return  bookService.loadList(pageNo,pageSize,searchBook);
    }
    @PostMapping("/addBook")
    public Result addBook(@RequestBody Book book){
        int i = bookService.addBook(book);
        if(i > 0) return Result.success("添加成功！");
        return Result.error("添加失败！");
    }
    @DeleteMapping("/deleteBook")
    public Result deleteBatchBook(@RequestBody List<Integer> id){
        int i = bookService.deleteBook(id);
        if(i > 0) return Result.success("删除成功！");
        return Result.error("删除失败！");
    }
    @PutMapping("/updateBook")
    public Result updateBook(@RequestBody Book book ){
        int i = bookService.updateBook(book);
        if(i > 0) return Result.success("修改成功！");
        return Result.error("修改失败！");
    }
}
